package com.zimmur.service.impl.base;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zimmur.dao.base.AppVersionDao;
import com.zimmur.model.base.AppVersion;
import com.zimmur.model.base.AppVersionExample;
import com.zimmur.service.base.IAppVersionService;

@Service("appVersionService")
public class AppVersionServiceImpl implements IAppVersionService {
	@Resource
	private AppVersionDao appVersionDao;
	
	@Override
	public AppVersion checkVersion(Integer curVersion) {
		AppVersionExample example = new AppVersionExample();
		example.or().andVersionNoGreaterThan(curVersion);
		example.setOrderByClause("version_no DESC");
		List<AppVersion> versions = appVersionDao.selectByExampleWithBLOBs(example);
		if(!versions.isEmpty()){
			return versions.get(0);
		}
		return null;
	}

	@Override
	public AppVersion getVersion(Integer curVersion) {
		AppVersionExample example = new AppVersionExample();
		example.or().andVersionNoEqualTo(curVersion);
		List<AppVersion> versions = appVersionDao.selectByExampleWithBLOBs(example);
		if(!versions.isEmpty()){
			return versions.get(0);
		}
		return null;
	}

}
